package com.example.rab.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @projectName: Book
 * @package: com.example.rab.config
 * @className: EsConfig
 * @author: zzh
 * @description: TODO
 * @version: 1.0
 */
@Configuration
public class EsConfig {
    @Bean(name = "directConnectionESClient")
    public ElasticsearchClient directConnectionESClient(){
        String serverUrl = "http://localhost:9200";
        RestClient restClient = RestClient
                .builder(HttpHost.create(serverUrl))
                .build();
        ElasticsearchTransport transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());
        return new ElasticsearchClient(transport);
    };

}
